<?php


namespace App\Api\Models;


use Illuminate\Database\Eloquent\Model;

class Live extends Model
{
    protected $table = 'cmc_live_studio';

    /**
     * 获取直播列表所有数据
     * @return mixed
     */
    static public function getList($order='desc',$order_line='created_at'){
        $data = self::where('is_play',1)->get(['live_title','live_image','anchor_name','is_play']);
        if (empty($data)) return [];
        return $data;
    }

    // 访问器
    public function getLiveImageAttribute($value)
    {
        return config('aliyun.cui').$this->attributes['live_image'];
    }
    /**
     * 根据id获取开播主播的单条数据
     * @param $id
     */
    static public function getAnchorOnce($id){
        if (empty($id) || !is_numeric($id)) return [];
        $data = self::join('cmc_live_anchor','cmc_live_studio.anchor_id','=','cmc_live_anchor.id')->where('cmc_live_anchor.id',$id)
            ->get(['cmc_live_studio.id','cmc_live_anchor.anchor_name','live_title','live_image','play_url','cmc_live_anchor.is_play'])
            ->toArray();
        if (empty($data)) return [];
        return $data;
    }

    /**
     * 根据id查询该主播下的所有回放地址
     * @param $id
     */
    static public function getPlayBack($id){
        $data = self::join('cmc_live_anchor','cmc_live_studio.anchor_id','=','cmc_live_anchor.id')
            ->where('cmc_live_studio.is_play',0)
            ->get(['cmc_live_studio.stream_name','cmc_live_studio.anchor_name','cmc_live_studio.playback_record_id']);
        if (empty($data)) return [];
        return $data;
    }

    /**
     * cuiqun
     * 查询单条回放
     * @param $id
     */
    static public function getPlayBackOnce($id){
        $data = self::where('cmc_live_studio.id',$id)
            ->get(['id','stream_name','live_title','anchor_name','add_time','playback_record_id']);
        if (empty($data)) return [];
        return $data;
    }
}